//
//  ViewController.swift
//  Demo
//
//  Created by 章旭松 on 16/8/31.
//  Copyright © 2016年 章旭松. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        useNSURLComponents()
        useEncode()
        useAndroid()
    }
}

extension ViewController {
    func useNSURLComponents() {
        let rawUrlString = "https://xxx/index.html?func=useNSURLComponents"
        let key = "qresult"
        let value = "http://qd.xxx.com/?paymentCode=ZA20632016080917074300000000268043"
        let newUrlString = rawUrlString.appendQueryParameter(key: key, value: value)
        print("useNSURLComponents：")
        print(newUrlString)
    }
}

extension ViewController {
    func useEncode() {
        let rawUrlString = "https://xxx/index.html?func=useEncode"
        let key = "qresult"
        let value = "http://qd.xxx.com/?paymentCode=ZA20632016080917074300000000268043"
        if let valueEncode = value.urlEncode() {
            let newUrlString = rawUrlString + "?" + key + "=" + valueEncode
            print("useEncode：")
            print(newUrlString)
        }
    }
}

extension ViewController {
    func useAndroid() {
        let rawUrlString = "https://xxx/index.html?func=useAndroid"
        let key = "qresult"
        let value = "http://qd.xxx.com/?paymentCode=ZA20632016080917074300000000268043"
        let newUrlString = rawUrlString.appendQueryParameterUseEncode(key: key, value: value)
        print("useAndroid：")
        print(newUrlString)
    }
}

